<?php

namespace app\models;

use Yii;

/**
 * This is the model class for table "notice".
 *
 * @property integer $id
 * @property string $title
 * @property string $content
 * @property integer $created_at
 * @property integer $type
 * @property integer $sort
 */
class Notice extends \yii\db\ActiveRecord
{
    const TYPE_REGISTER = 1;//注册页面
    const TYPE_INDEX = 2;//首页面
    public static $typeArray = array(
        self::TYPE_REGISTER => '注册页面',
        self::TYPE_INDEX => '首页面',
    );
    /**
     * @inheritdoc
     */
    public static function tableName()
    {
        return 'notice';
    }

    /**
     * @inheritdoc
     */
    public function rules()
    {
        return [
            [['content'], 'string'],
            [['created_at','type'], 'integer'],
            [['title'], 'string', 'max' => 128],
            [['sort'], 'default', 'value' => 0],
        ];
    }

    /**
     * @inheritdoc
     */
    public function attributeLabels()
    {
        return [
            'id' => 'ID',
            'title' => '标题',
            'content' => '内容',
            'created_at' => '创建时间',
            'type' => '页面类型',
            'sort' => '排序',
        ];
    }

    public function save($runValidation = true, $attributeNames = null)
    {
        if($this->isNewRecord) {
            $this->created_at = time();
        }
        return parent::save($runValidation, $attributeNames);
    }
}
